<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    p {
    width: 200px;
    height: 200px;
    resize: horizontal;
    overflow: scroll;
}

</style>
<body>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. A aut qui labore rerum placeat similique hic
        consequatur tempore doloribus aliquid alias, nobis voluptates. Perferendis, voluptate placeat esse soluta
        deleniti id!</p>
        <ul id="test1">
            <li>1</li>
            <li>2</li>
            <li>3</li>
        </ul>
</body>


<script>
  var oUL = document.getElementById("test");
    var oLi = oUl.getElementByTagName("li");
    for(var i=0;i<oLi.length;i++){
        oLi[i].index = i;
        oLi[i].onclick = (function(a){
            return function(){
                alert(a);
            }
        })(i)
    }

</script>
</html>